//
//  ZCSListenHeaderView.m
//  聆听FM
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 Dark. All rights reserved.
//

#import "ZCSListenHeaderView.h"

@implementation ZCSListenHeaderView



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleImageView = [[UIImageView alloc] init];
        self.titleImageView.image = [UIImage imageNamed:@"title"];
        [self addSubview:_titleImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:18];
        [self addSubview:_titleLabel];
        
        self.littleImage = [[UIImageView alloc] init];
        self.littleImage.image = [UIImage imageNamed:@"简介"];
        [self addSubview:_littleImage];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.font = [UIFont systemFontOfSize:13];
        self.contentLabel.alpha = 0.5;
        self.contentLabel.numberOfLines = 0;
        [self addSubview:_contentLabel];
        
        self.label = [[UILabel alloc] init];
        self.label.text = @"小编:";
        self.label.textAlignment = 2;
        self.label.font = [UIFont systemFontOfSize:12];
        [self addSubview:_label];
        
        self.nameImage = [[UIImageView alloc] init];
        self.nameImage.layer.masksToBounds = YES;
        [self addSubview:_nameImage];
        
        self.nameLabel = [[UILabel alloc] init];
        self.nameLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:_nameLabel];
        self.nameLabel.textAlignment = 2;
        
        
        
        
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.backgroundColor = [UIColor whiteColor];
    self.titleImageView.frame = CGRectMake(15 * FITWIDTH, 25 * FITHEIGHT, 32 * FITWIDTH, 32 * FITHEIGHT);
    self.titleLabel.frame = CGRectMake(self.titleImageView.frame.origin.x + self.titleImageView.frame.size.width + 10 * FITWIDTH, self.titleImageView.frame.origin.y, SCREENWIDTH - 104 * FITWIDTH, self.titleImageView.frame.size.height);
    self.littleImage.frame = CGRectMake(100 * FITWIDTH, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 20 * FITHEIGHT, 175 * FITWIDTH, 20 * FITHEIGHT);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13], NSFontAttributeName, nil];
    CGRect newRect = [self.model.intro boundingRectWithSize:CGSizeMake(SCREENWIDTH - 20 * FITWIDTH, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.contentLabel.frame = CGRectMake(10 * FITWIDTH, self.littleImage.frame.origin.y + self.littleImage.frame.size.height + 10, newRect.size.width, newRect.size.height);
    self.label.frame = CGRectMake(220 * FITWIDTH, self.frame.size.height - 32 * FITHEIGHT, 40 * FITWIDTH, 12 * FITHEIGHT);
    self.nameImage.frame = CGRectMake(self.label.frame.origin.x + self.label.frame.size.width + 5, self.label.frame.origin.y, 14 * FITWIDTH, 14 * FITHEIGHT);
    self.nameLabel.frame = CGRectMake(self.nameImage.frame.origin.x + self.nameImage.frame.size.width, self.nameImage.frame.origin.y, 80 * FITWIDTH, 12 * FITHEIGHT);
    self.nameImage.layer.cornerRadius = 6 * FITWIDTH;
    [self.nameLabel sizeToFit];
}

- (void)setModel:(ZCSListenListDetailModel *)model
{
    if (_model != model) {
        _model = model;
        self.titleLabel.text = model.title;
        self.contentLabel.text = model.intro;
        [self.nameImage sd_setImageWithURL:[NSURL URLWithString:model.smallLogo] placeholderImage:[UIImage imageNamed:@"placeHolder"]];
        self.nameLabel.text = model.nickname;
    }
}


@end
